import {createStoreBindings} from "mobx-miniprogram-bindings"
import {store} from "../../store/store"
import http from "../../utils/request"
import toast from '@vant/weapp/toast/toast';
Page({
  data: {
    fileList:[],
  },
  onLoad(){
    this.storeBindings = createStoreBindings(this,{
      store,
      fields:["sectionList","categoryData"],
      actions:["updateShowSection","getSectionList","updateSection","setToastMessage"]
    })
  },
  afterRead(event) {//文件上传回调
    const file = event.detail.file;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      filePath: file.path,
      name: 'file',
      url: 'http://localhost:8080/upload/uploadImg',
      header:{token:wx.getStorageSync('token')},
      success:(res)=>{
        // 上传完成需要更新 fileList
        const fileList = this.data.fileList;
        fileList.push({ ...file, url: res.data });
        this.setData({ fileList });
        console.log(this.data.fileList)
      },
      fail:(res)=>{
        console.log(res)
      }
    })
  },
  deleteImg(event){
    const fileList = this.data.fileList;
    fileList.splice(event.detail.index,1)
    this.setData({fileList})
  },
  bindOversize(){
    toast.fail({
      message:"视频文件过大",
      duration:1500
    })
  }
})